/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.tables;

import TimeRecording.enums.EventType;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author cbegg
 */
@Entity
@Table(name = "event")
@NamedQueries({
    @NamedQuery(name = "Event.findAll", query = "SELECT e FROM Event e"),
    @NamedQuery(name = "Event.findByAutoId", query = "SELECT e FROM Event e WHERE e.autoId = :autoId"),
    @NamedQuery(name = "Event.findByEventTime", query = "SELECT e FROM Event e WHERE e.eventTime = :eventTime"),
    @NamedQuery(name = "Event.findByAcknowledged", query = "SELECT e FROM Event e WHERE e.acknowledged = :acknowledged"),
    @NamedQuery(name = "Event.findByAcknowledgedTime", query = "SELECT e FROM Event e WHERE e.acknowledgedTime = :acknowledgedTime")})

public class Event implements Serializable {

    private static final long serialVersionUID = 1L;

    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "auto_id")
    private long autoId;

    @Basic(optional = false)
    @Column(name = "event_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date eventTime;

    @Column(name = "acknowledged")
    private boolean acknowledged;

    @Basic(optional = false)
    @Column(name = "acknowledged_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date acknowledgedTime;

    @Column(name = "event_type")
    private EventType eventType;

    @JoinColumn(name = "employee_id", referencedColumnName = "employee_id")
    @ManyToOne
    private Employee employeeId;

    @JoinColumn(name = "acknowledged_by_id", referencedColumnName = "employee_id")
    @ManyToOne
    private Employee acknowledgedById;

    public Event() {
    }

    public Event(long autoId) {
	this.autoId = autoId;
    }

    public Event(long autoId, Date eventTime, Date acknowledgedTime) {
	this.autoId = autoId;
	this.eventTime = eventTime;
	this.acknowledgedTime = acknowledgedTime;
    }

    public long getAutoId() {
	return autoId;
    }

    public void setAutoId(long autoId) {
	this.autoId = autoId;
    }

    public Date getEventTime() {
	return eventTime;
    }

    public void setEventTime(Date eventTime) {
	Date oldeventTime = this.eventTime;
	this.eventTime = eventTime;
	changeSupport.firePropertyChange("eventTime", oldeventTime, eventTime);
    }

    public boolean getAcknowledged() {
	return acknowledged;
    }

    public void setAcknowledged(boolean acknowledged) {
	boolean oldacknowledged = this.acknowledged;
	this.acknowledged = acknowledged;
	changeSupport.firePropertyChange("acknowledged", oldacknowledged, acknowledged);
    }

    public Date getAcknowledgedTime() {
	return acknowledgedTime;
    }

    public void setAcknowledgedTime(Date acknowledgedTime) {
	Date oldacknowledgedTime = this.acknowledgedTime;
	this.acknowledgedTime = acknowledgedTime;
	changeSupport.firePropertyChange("acknowledgedTime", oldacknowledgedTime, acknowledgedTime);
    }

    public EventType getEventType() {
	return eventType;
    }

    public void setEventType(EventType eventType) {
	EventType oldeventType = this.eventType;
	this.eventType = eventType;
	changeSupport.firePropertyChange("eventType", oldeventType, eventType);
    }

    public Employee getEmployeeId() {
	return employeeId;
    }

    public void setEmployeeId(Employee employeeId) {
	Employee oldemployeeId = this.employeeId;
	this.employeeId = employeeId;
	changeSupport.firePropertyChange("employeeId", oldemployeeId, employeeId);
    }

    public Employee getAcknowledgedById() {
	return acknowledgedById;
    }

    public void setAcknowledgedById(Employee acknowledgedById) {
	Employee oldacknowledgedById = this.acknowledgedById;
	this.acknowledgedById = acknowledgedById;
	changeSupport.firePropertyChange("acknowledgedById", oldacknowledgedById, acknowledgedById);
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 43 * hash + (int) (this.autoId ^ (this.autoId >>> 32));
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Event other = (Event) obj;
        if (this.autoId != other.autoId) {
            return false;
        }
        return true;
    }
    
    @Override
    public String toString() {
	return "TimeRecording.tables.EventsLog[autoId=" + autoId + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
	changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
	changeSupport.removePropertyChangeListener(listener);
    }
}